ig.module('game.entities.chair').requires('impact.entity').defines(function(){
    Chair = ig.Entity.extend({
        size: {
            x: 165,
            y: 165
        },
        isMouseEnter: false,
        seat: 0,
        player: null,
        enabled: true,
        cardDataList: null,
        animSheet: new ig.AnimationSheet('media/chair.png', 165, 165),
        init: function(x, y, settings){
            this.parent(x, y, settings);
            switch (settings.type) {
                case Chair.LEFT_TOP:
                    this.addAnim('idle', 0, [4]);
                    this.addAnim('hover', 0, [0]);
                    break;
                case Chair.LEFT_BOTTOM:
                    this.addAnim('idle', 0, [7]);
                    this.addAnim('hover', 0, [3]);
                    break;
                case Chair.RIGHT_TOP:
                    this.addAnim('idle', 0, [5]);
                    this.addAnim('hover', 0, [1]);
                    break;
                case Chair.RIGHT_BOTTOM:
                    this.addAnim('idle', 0, [6]);
                    this.addAnim('hover', 0, [2]);
                    break;
            }
            this.seat = settings.seat;
            this.cardDataList = new Array();
        },
        update: function(){
            if (this.enabled) {
                if ((ig.input.mouse.x > this.pos.x && ig.input.mouse.x < this.pos.x + this.size.x) &&
                (ig.input.mouse.y > this.pos.y && ig.input.mouse.y < this.pos.y + this.size.y)) {
                    if (!this.isMouseEnter) {
                        this.isMouseEnter = true;
                    }
                }
                else {
                    if (this.isMouseEnter) {
                        this.isMouseEnter = false;
                    }
                }
                
                if (ig.input.released('click') && this.isMouseEnter) {
                    this.mouseclick();
                }
            }
            else {
                if (this.isMouseEnter) {
                    this.isMouseEnter = false;
                }
                this.mouseenter();
            }
        },
        draw: function(){
            this.parent();
        },
        mouseenter: function(){
            this.currentAnim = this.anims.hover.rewind();
        },
        mouseout: function(){
            this.currentAnim = this.anims.idle.rewind();
        },
        mouseclick: function(){
            ig.game.host.command("JOIN", this.seat);
        },
        addCard: function(cardData, completed){
            this.cardDataList.push(cardData);
            new ig.Tween(cardData.card, {
                pos: {
                    x: cardData.pos.x,
                    y: cardData.pos.y
                }
            }, 0.25, function(){
                if (cardData.dealCard != null) 
                    cardData.card.setData(cardData.dealCard.Number, cardData.dealCard.Type);
                completed();
            });
        }
    });
    Chair.LEFT_TOP = 'left-top';
    Chair.LEFT_BOTTOM = 'left-bottom';
    Chair.RIGHT_TOP = 'right-top';
    Chair.RIGHT_BOTTOM = 'right-bottom';
});
